package com.wcgksoft.mobileservice.Account.alarm;


import com.wcgksoft.common.util.MsgInfo;
import com.wcgksoft.entity.Alert.Alarm;
import com.wcgksoft.service.alarm.AlarmService;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 告警
 *
 * @author Administrator
 */
@Controller
@RequestMapping("mobile/alarm")
public class AppAlarmController {

    @Autowired
    private AlarmService alarmService;

    /**
     * 列表
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "list")
    public MsgInfo list(
            @RequestParam(value = "proid", required = false) String proid
    ) {
        MsgInfo msgInfo = new MsgInfo();
        DetachedCriteria criteria = DetachedCriteria.forClass(Alarm.class);
        criteria.add(Restrictions.eq("level", "高级"));
        criteria.createAlias("departProjectData", "departProjectData");
        criteria.add(Restrictions.eq("departProjectData.enterpriseProject.id", proid));
        List<Alarm> list = alarmService.findByConditions(criteria);
        if(list.size()>0){
            msgInfo.setCode(0);
            msgInfo.setMsg("查询成功");
            msgInfo.setData(list);
        }else{
            msgInfo.setCode(1);
            msgInfo.setMsg("无数据");
            msgInfo.setData(null);
        }
        return msgInfo;
    }






}
